package org.agile2soft.nexoma.core.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.agile2soft.nexoma.expedient.entity.EntryRegNumbers;
import org.agile2soft.nexoma.expedient.entity.Expedient;

@Entity
@Table(name = "REQUEST")
@SuppressWarnings({"serial"})
public class Request implements java.io.Serializable {

    private Integer id;
    private EntryRegNumbers entryRegNumbers;
    private Expedient expedient;
    private byte[] proposal;
    private byte[] content;
    private Date date;
    private boolean initial;
    private boolean type;
    private Set<UserRequest> citizenRequests = new HashSet<UserRequest>(0);


    public Request() {
    }

    public Request(byte[] request, Date date, boolean initial,
            boolean type) {
        this.content = request;
        this.date = date;
        this.initial = initial;
        this.type = type;
    }

    public Request(EntryRegNumbers entryRegNumbers,
            Expedient expedient, byte[] proposal, byte[] request,
            Date date, boolean initial, boolean type,
            Set<UserRequest> citizenRequests) {
        this.entryRegNumbers = entryRegNumbers;
        this.expedient = expedient;
        this.proposal = proposal;
        this.content = request;
        this.date = date;
        this.initial = initial;
        this.type = type;
        this.citizenRequests = citizenRequests;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "SOL_ID", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "REG_ID")
    public EntryRegNumbers getEntryRegNumbers() {
        return this.entryRegNumbers;
    }

    public void setEntryRegNumbers(EntryRegNumbers entryRegNumbers) {
        this.entryRegNumbers = entryRegNumbers;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "EXP_ID")
    public Expedient getExpedient() {
        return this.expedient;
    }

    public void setExpedient(Expedient expedient) {
        this.expedient = expedient;
    }

    @Column(name = "SOL_PROPOSAL")
    public byte[] getProposal() {
        return this.proposal;
    }

    public void setProposal(byte[] proposal) {
        this.proposal = proposal;
    }

    @Column(name = "SOL_CONTENT", nullable = false)
    public byte[] getContent() {
        return this.content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "SOL_DATE", nullable = false, length = 10)
    public Date getDate() {
        return this.date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Column(name = "SOL_INITIAL", nullable = false)
    public boolean isInitial() {
        return this.initial;
    }

    public void setInitial(boolean initial) {
        this.initial = initial;
    }

    @Column(name = "SOL_TYPE", nullable = false)
    public boolean isType() {
        return this.type;
    }

    public void setType(boolean type) {
        this.type = type;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "request")
    public Set<UserRequest> getCitizenRequests() {
        return this.citizenRequests;
    }

    public void setCitizenRequests(
            Set<UserRequest> citizenRequests) {
        this.citizenRequests = citizenRequests;
    }

}
